package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type JsonResStruct[T interface{}] struct {
	Code string      `json:"code"`
	Msg  interface{} `json:"msg"`
	// 一级分类集合
	Data T `json:"data"`
}

type JsonResStructMsg struct {
	Code string      `json:"code"`
	Msg  interface{} `json:"msg"`
}

func ReturnSuccess[T interface{}](c *gin.Context, code string, msg interface{}, data T) {
	jsonRes := &JsonResStruct[T]{
		Code: code,
		Msg:  msg,
		Data: data,
	}
	c.JSON(http.StatusOK, jsonRes)
}

func ReturnErr(c *gin.Context, code string, msg interface{}) {
	jsonRes := &JsonResStructMsg{
		Code: code,
		Msg:  msg,
	}
	c.JSON(http.StatusOK, jsonRes)
}
